﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ServerPlatform.Configuration;

namespace WebApp
{
    public partial class _default : System.Web.UI.Page
    {
        private static readonly string TestEntity = "3AD41DF0-D4B7-4F31-8892-3F2AFFB25686";
        protected void Page_Load(object sender, EventArgs e)
        {

            Guid id = new Guid(TestEntity);
            MapEntities.MapDataRequest req = DataProviderSection.GetMapDataProviderObject().GetMapData(id, Page.Request.Url.AbsoluteUri);
            if (req == null)
            {
                req = MapEntities.MapDataRequest.CreateEmpty();
                req.Id = id;
                req.ShapeBindingRuleDataList.Add(new MapEntities.ShapeItemBindingRule());
                req.ShapeBindingRuleDataList[0].SpatialField = "temp";
                req.ShapeBindingRuleDataList[0].ListingRule = new MapEntities.ListingBindingRule() { KeyField = "ID", Request = new DALEntities.ViewRequest() { ProviderName = "TurkiyeMap", ViewName = "Cities" } };
                req.ShapeBindingRuleDataList[0].BindingRule = new MapEntities.ItemBindingRule() { KeyField = "ID", Request = new DALEntities.ViewRequest() { ProviderName = "TurkiyeMap", ViewName = "Cities" } };
                req.ShapeBindingRuleDataList[0].CustomLayer = "default";
                req.ShapeBindingRuleDataList[0].TextBinding = "{City}";
                req.ShapeBindingRuleDataList[0].TooltipBinding = "Code of {City} is {ID}";
                req.ShapeBindingRuleDataList[0].BindingRule.ValueField = "ID";
                req.ShapeBindingRuleDataList[0].Visualization.BackgroundVisialization.DataType = DALEntities.DataType.Integer;
                req.ShapeBindingRuleDataList[0].Visualization.BackgroundVisialization.Mode = MapEntities.ShapeBackgroundVisualizationMode.Automatic;
                req.ShapeBindingRuleDataList[0].Visualization.BackgroundVisialization.Automatic.ColoringInfo.Mode = MapEntities.ColoringMode.Gradient;
                req.ShapeBindingRuleDataList[0].Visualization.BackgroundVisialization.Automatic.ColoringInfo.Level = MapEntities.TransparencyLevel.MidiumMinus;
                req.ShapeBindingRuleDataList[0].Visualization.BackgroundVisialization.Automatic.ColoringInfo.ColorName = System.Drawing.KnownColor.Red;
                req.ShapeBindingRuleDataList[0].Behaviour.ItemTransparencyLevel = MapEntities.TransparencyLevel.Middle;


                req.ShapeBindingRuleDataList[0].Behaviour.LeftMouseClick.RedirectAddress = "http://localhost/temp.aspx?id={ID}";
                req.MapProperties.BackgroundMode = MapEntities.Mode.AerialWithLabels;
                req.MapProperties.Center = new MapEntities.GeoPoint(39, 35);
                req.MapProperties.ZoomLevel = 6;
                HttpContext.Current.Application[req.Id.ToString()] = req;
                ctlEditor.Edit(req);
                ctlMap.Bind(req);
            }
            else if (!Page.IsPostBack)
            {
                ctlEditor.Edit(req);
                ctlMap.Bind(req);
            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            MapEntities.MapDataRequest req = ctlEditor.EndEdit();
            HttpContext.Current.Application[req.Id.ToString()] = req;
            ctlMap.Bind(req);
            UpdatePanel1.Update();
        }
    }
}